package com.dd.view;

import org.nutz.boot.starter.freemarker.FreeMarkerConfigurer;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.View;
import org.nutz.mvc.view.DefaultViewMaker;

public class DDView extends DefaultViewMaker{
    public static final String VIEW_FAIL = "fail";
    public static final String VIEW_FREEMAKER = "fm";
    protected String iocName = "freeMarkerConfigurer";
    FreeMarkerConfigurer freeMarkerConfigurer;
    public DDView() {
    	
    }

    @Override
    public View make(Ioc ioc, String type, String value) {
        if (VIEW_FREEMAKER.equals(type)) {
    		    if (freeMarkerConfigurer == null) {
    		        for (String name : ioc.getNames()) {
                        if (iocName.equals(name)) {
                            freeMarkerConfigurer = ioc.get(FreeMarkerConfigurer.class);
                            break;
                        }
                    }
    		        if (freeMarkerConfigurer == null) {
    		            freeMarkerConfigurer = new FreeMarkerConfigurer();
    		            freeMarkerConfigurer.init();
    		        }
    		    }
    			return new FreeMakerView(freeMarkerConfigurer, value);
        }
        return super.make(ioc, type, value);
    }

}
